package com.xc.h05.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class R {
    private int code;
    private String msg;
    private Object data;

    public static R ok(Object data){
        R r = new R();
        r.setCode(1);
        r.setMsg("请求成功");
        r.setData(data);
        return r;
    }

    public static R fail(){
        R r = new R();
        r.setCode(0);
        r.setMsg("请求失败");
        r.setData(null);
        return r;
    }

    public static R fail(String msg){
        R r = new R();
        r.setCode(0);
        r.setMsg(msg);
        r.setData(null);
        return r;
    }

    public static R error(){
        R r = new R();
        r.setCode(-1);
        r.setMsg("错误");
        r.setData(null);
        return r;
    }
}
